package com.hspedu.newData.dmsxl.贪心算法;
/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-26 
 * @Version: 1.0
 */

public class LC738单调递增的数字 {

    public int monotoneIncreasingDigits(int n) {
        for (int i = n; i >= 0; i--) {
            if (check(i)){
                return i;
            }
        }
        return 0;
    }

    public boolean check(int i){
        String s = i+"";
        char[] charArray = s.toCharArray();
        for (int j = charArray.length - 1; j >= 1; j--) {
            if (charArray[j] < charArray[j-1]){
                return false;
            }
        }
        return true;

    }
}
